package com.kly.sc.api.application.service.user.impl;

import com.fqgj.common.api.Page;
import com.kly.sc.api.application.controller.product.response.SubscriptionsVO;
import com.kly.sc.api.application.controller.user.request.WlmUserRequest;
import com.kly.sc.api.application.controller.user.response.UserLikeResponse;
import com.kly.sc.api.application.helper.RequestLocalInfo;
import com.kly.sc.api.application.service.user.UserLikeService;
import com.kly.sc.api.application.utils.Result;
import com.kly.sc.api.application.utils.RpcUtils;
import com.kly.user.dto.LikeUserDto;
import com.kly.user.service.WlmService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserLikeServiceImpl implements UserLikeService {


    @Resource
    private WlmService wlmService;

    @Override
    public Result<List<UserLikeResponse>> getUserLikeList(WlmUserRequest wlmUserRequest, Boolean showTurnOnsFlag) {
        String userCode = RequestLocalInfo.getCurrentUser().getUserCode();
        Page page = new Page();
        page.setPageSize(wlmUserRequest.getPageSize());
        page.setCurrentPage(wlmUserRequest.getPageNum());

        List<LikeUserDto> likeUserDtoList = RpcUtils.getResult(wlmService.likeList(userCode, page));
        List<UserLikeResponse> userLikeResponseList = new ArrayList<>();
        if (likeUserDtoList != null) {
            userLikeResponseList = likeUserDtoList.stream().map(likeUserDto -> UserLikeResponse.toResponse(likeUserDto, showTurnOnsFlag)).collect(Collectors.toList());
        }
        return Result.ok(userLikeResponseList);
    }

    @Override
    public Result<Integer> getUserLikeCount() {
        String userCode = RequestLocalInfo.getCurrentUser().getUserCode();
        Integer likeCount = RpcUtils.getResult(wlmService.likeCount(userCode));
        return Result.ok(likeCount);
    }
}
